package com.disgnpattern.learn.chapter2;

/**
 * @author dxy
 * @version 1.0
 * @date 2021/10/21 14:50
 * @decripton 满减返现
 */
public class CashReturn implements CashSuper{
    private double moneyCondition;
    private double moneyReturn;

    public CashReturn(double moneyCondition, double moneyReturn) {
        this.moneyCondition = moneyCondition;
        this.moneyReturn = moneyReturn;
    }

    @Override
    public double acceptCash(double totalPrice) {
        double price = totalPrice;
        if(totalPrice > this.moneyCondition) {
            price = totalPrice - Math.floor(totalPrice / moneyCondition) * moneyReturn;
        }
        return price;
    }
}
